package com.freedom.reader;

import com.freedom.service.WriteReadService;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;


;

public class MenuActivity extends TabActivity 
{

	private final String TAG="www";
	private TextView textView;
	WriteReadService WriteReadService;
	TabHost mTabHost;
	
	
	
    public void onCreate(Bundle savedInstanceState) 
    {
        
    	super.onCreate(savedInstanceState);
        setContentView(R.layout.main); 
        
        //读写服务
        WriteReadService = new WriteReadService(this);     
       
        //////////////////////
      	//取得TabHost对象
        mTabHost = getTabHost();
        //Log.i(TAG,"success");
        //添加标签，建newTabSpec，设标签，图标，和内容
        mTabHost.addTab(mTabHost.newTabSpec("menu")
	    		.setIndicator("菜单",getResources().getDrawable(R.drawable.menu))
	    		.setContent(R.id.menuid));
		
        //MenuActivity
        
        //Log.i(TAG,"success");
        
        
        mTabHost.addTab(mTabHost.newTabSpec("reading")
        		.setIndicator("正在阅读",getResources().getDrawable(R.drawable.reading))
        		.setContent(R.id.readingid));
        //ReadingActivity
        
        
        mTabHost.addTab(mTabHost.newTabSpec("other")
        		.setIndicator("多媒体", getResources()
				.getDrawable(R.drawable.media))
				.setContent(R.id.mediaid));
        //OtherActivity
        
        //设置背景
        mTabHost.setBackgroundColor(Color.BLACK);
        
        //设置当前显示哪一个标签
        mTabHost.setCurrentTab(0);
        
        //设置背景资源图片
        mTabHost.setBackgroundResource(R.drawable.mmenu);
        
        /*
        //标签切换处理事件
        mTabHost.setOnTabChangedListener(new OnTabChangeListener()
        {
	    	// TODO Auto-generated method stub
            @Override
            public void onTabChanged(String tabId) 
            {
  	    	  	Dialog dialog = new AlertDialog.Builder(MenuActivity.this)
  	    	  			.setTitle("提示")
  	    	  			.setMessage("当前选中"+tabId+"标签")
  	    	  			.setPositiveButton("确定",
  	    	  			new DialogInterface.OnClickListener() 
  	    	  			{
  	    	  				public void onClick(DialogInterface dialog, int whichButton)
  	    	  				{
  	    	  					dialog.cancel();
  	    	  				}
  	    	  			}).create();
	    	  
  	    	  	dialog.show();
            }            
        });
        */
    	
        
        
        /////////////////////////////////////////////////////////////
        //打开按钮监听
        ImageButton openButton=(ImageButton) this.findViewById(R.id.openButton);
        openButton.setOnClickListener(new Button.OnClickListener()
		{

			@Override
			public void onClick(View v) 
			{
				mTabHost.setCurrentTab(1);
				
				//找到要显示文本的地方
		        textView=(TextView)findViewById(R.id.content);
		        //设置背景图片
		        textView.setBackgroundResource(R.drawable.background);
		        //textView.setTextColor(Color.BLACK);
				try 
		        {
					String res=WriteReadService.readFile("normal");
					textView.setText(res);
					//Log.i(TAG, res);
				} 
		        catch (Exception e) 
		        {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}						
		});
        
        ///////////////////////////////////////////////////////////////////////
        //退出按钮
        ImageButton exitButton=(ImageButton) this.findViewById(R.id.exitButton);
        //exitButton.setImageDrawable(getResources().getDrawable(R.drawable.exit));
        exitButton.setOnClickListener(new Button.OnClickListener()
		{

			

			@Override
			public void onClick(View v) 
			{
				// TODO Auto-generated method stub
				MenuActivity.this.finish();
			}
        	
		}
    	);
    }


	
}
